from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-14 14:02:21.015027
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 14, May, 2022
Time: 14:02:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.2837
Nobs: 656.000 HQIC: -49.6606
Log likelihood: 8079.53 FPE: 2.13335e-22
AIC: -49.8992 Det(Omega_mle): 1.86178e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.320220 0.060970 5.252 0.000
L1.Burgenland 0.105356 0.038953 2.705 0.007
L1.Kärnten -0.109465 0.020419 -5.361 0.000
L1.Niederösterreich 0.197475 0.081170 2.433 0.015
L1.Oberösterreich 0.122479 0.080231 1.527 0.127
L1.Salzburg 0.256995 0.041380 6.211 0.000
L1.Steiermark 0.044057 0.054300 0.811 0.417
L1.Tirol 0.101326 0.043743 2.316 0.021
L1.Vorarlberg -0.063197 0.038769 -1.630 0.103
L1.Wien 0.030239 0.071032 0.426 0.670
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.047865 0.130154 0.368 0.713
L1.Burgenland -0.032039 0.083153 -0.385 0.700
L1.Kärnten 0.040742 0.043590 0.935 0.350
L1.Niederösterreich -0.184412 0.173275 -1.064 0.287
L1.Oberösterreich 0.448377 0.171269 2.618 0.009
L1.Salzburg 0.284600 0.088334 3.222 0.001
L1.Steiermark 0.107752 0.115915 0.930 0.353
L1.Tirol 0.310744 0.093378 3.328 0.001
L1.Vorarlberg 0.021865 0.082761 0.264 0.792
L1.Wien -0.037437 0.151633 -0.247 0.805
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187092 0.031296 5.978 0.000
L1.Burgenland 0.089734 0.019995 4.488 0.000
L1.Kärnten -0.007656 0.010481 -0.730 0.465
L1.Niederösterreich 0.254194 0.041665 6.101 0.000
L1.Oberösterreich 0.155147 0.041183 3.767 0.000
L1.Salzburg 0.042315 0.021240 1.992 0.046
L1.Steiermark 0.024856 0.027872 0.892 0.373
L1.Tirol 0.084424 0.022453 3.760 0.000
L1.Vorarlberg 0.053439 0.019900 2.685 0.007
L1.Wien 0.117684 0.036461 3.228 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111190 0.031395 3.542 0.000
L1.Burgenland 0.045897 0.020058 2.288 0.022
L1.Kärnten -0.014019 0.010514 -1.333 0.182
L1.Niederösterreich 0.183136 0.041796 4.382 0.000
L1.Oberösterreich 0.327699 0.041313 7.932 0.000
L1.Salzburg 0.101487 0.021307 4.763 0.000
L1.Steiermark 0.109952 0.027960 3.932 0.000
L1.Tirol 0.096044 0.022524 4.264 0.000
L1.Vorarlberg 0.059809 0.019963 2.996 0.003
L1.Wien -0.022074 0.036576 -0.604 0.546
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114064 0.058413 1.953 0.051
L1.Burgenland -0.043590 0.037319 -1.168 0.243
L1.Kärnten -0.046234 0.019563 -2.363 0.018
L1.Niederösterreich 0.142780 0.077765 1.836 0.066
L1.Oberösterreich 0.160171 0.076865 2.084 0.037
L1.Salzburg 0.282046 0.039644 7.114 0.000
L1.Steiermark 0.055907 0.052022 1.075 0.283
L1.Tirol 0.165028 0.041908 3.938 0.000
L1.Vorarlberg 0.095777 0.037143 2.579 0.010
L1.Wien 0.076263 0.068053 1.121 0.262
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060061 0.046072 1.304 0.192
L1.Burgenland 0.031516 0.029435 1.071 0.284
L1.Kärnten 0.051506 0.015430 3.338 0.001
L1.Niederösterreich 0.207425 0.061336 3.382 0.001
L1.Oberösterreich 0.317087 0.060626 5.230 0.000
L1.Salzburg 0.041032 0.031268 1.312 0.189
L1.Steiermark 0.006577 0.041032 0.160 0.873
L1.Tirol 0.130845 0.033054 3.959 0.000
L1.Vorarlberg 0.065355 0.029296 2.231 0.026
L1.Wien 0.089394 0.053675 1.665 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174356 0.055291 3.153 0.002
L1.Burgenland 0.005038 0.035324 0.143 0.887
L1.Kärnten -0.065168 0.018517 -3.519 0.000
L1.Niederösterreich -0.096699 0.073609 -1.314 0.189
L1.Oberösterreich 0.203775 0.072757 2.801 0.005
L1.Salzburg 0.054110 0.037525 1.442 0.149
L1.Steiermark 0.242172 0.049242 4.918 0.000
L1.Tirol 0.500744 0.039668 12.623 0.000
L1.Vorarlberg 0.058321 0.035158 1.659 0.097
L1.Wien -0.074047 0.064415 -1.150 0.250
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148338 0.061311 2.419 0.016
L1.Burgenland 0.004201 0.039171 0.107 0.915
L1.Kärnten 0.060338 0.020534 2.938 0.003
L1.Niederösterreich 0.180697 0.081624 2.214 0.027
L1.Oberösterreich -0.056547 0.080680 -0.701 0.483
L1.Salzburg 0.205825 0.041611 4.946 0.000
L1.Steiermark 0.134734 0.054604 2.467 0.014
L1.Tirol 0.068843 0.043987 1.565 0.118
L1.Vorarlberg 0.143517 0.038986 3.681 0.000
L1.Wien 0.111873 0.071429 1.566 0.117
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374121 0.036118 10.358 0.000
L1.Burgenland -0.000438 0.023075 -0.019 0.985
L1.Kärnten -0.021535 0.012096 -1.780 0.075
L1.Niederösterreich 0.215357 0.048084 4.479 0.000
L1.Oberösterreich 0.227225 0.047527 4.781 0.000
L1.Salzburg 0.038499 0.024513 1.571 0.116
L1.Steiermark -0.014688 0.032166 -0.457 0.648
L1.Tirol 0.092898 0.025912 3.585 0.000
L1.Vorarlberg 0.053843 0.022966 2.344 0.019
L1.Wien 0.036584 0.042078 0.869 0.385
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036716 0.116129 0.173517 0.142547 0.100359 0.084425 0.039551 0.211224
Kärnten 0.036716 1.000000 -0.019766 0.134897 0.052492 0.089952 0.440763 -0.060559 0.093656
Niederösterreich 0.116129 -0.019766 1.000000 0.324284 0.128636 0.284922 0.073527 0.161819 0.297532
Oberösterreich 0.173517 0.134897 0.324284 1.000000 0.220923 0.309446 0.167681 0.150405 0.251566
Salzburg 0.142547 0.052492 0.128636 0.220923 1.000000 0.129984 0.097801 0.114965 0.130424
Steiermark 0.100359 0.089952 0.284922 0.309446 0.129984 1.000000 0.138596 0.117967 0.050007
Tirol 0.084425 0.440763 0.073527 0.167681 0.097801 0.138596 1.000000 0.069490 0.147122
Vorarlberg 0.039551 -0.060559 0.161819 0.150405 0.114965 0.117967 0.069490 1.000000 0.006482
Wien 0.211224 0.093656 0.297532 0.251566 0.130424 0.050007 0.147122 0.006482 1.000000